<?php defined( '_JEXEC' ) or die( 'Restricted access' ); 

class TableVote extends JTable
{
  var $id = null;
  var $sketchup_id = null;
  var $ip_address = null;
  var $session_id = null;
  var $time = null;

	function __construct(&$db)
	{
		parent::__construct( '#__sketchup_votes', 'id', $db );
	}

  /**
   * Returns false (don't allow) if the current IP address or session ID has
   * voted in the last 24 hours
   *
   * @return void
   * @author Joseph LeBlanc
   */

    function check()
    {
    
    $db =& JFactory::getDBO();

    $query = "SELECT count(*) FROM #__sketchup_votes". " WHERE (ip_address = " . $db->Quote($this->ip_address) . " AND session_id = " . 
    $db->Quote($this->session_id) . ")";
    $db->setQuery($query);
    $votes = $db->loadResult();

    // Also check the cookie variable
    $voted = JRequest::getVar(JUtility::getHash('sketchup'), '', 'cookie');

    if ($voted != '') {
        $votes++;
    }

    if ($votes > 0) {
      return false;
    }

    return true;
  }
}
